//
// Created by fanghr on 17-12-26.
//

#ifndef PROJECT_CAMERACALIBRATOR_H
#define PROJECT_CAMERACALIBRATOR_H

#include "../../../include.h"

class CameraCalibrator {
    std::vector< std::vector<cv::Point3f> > objectPoints;

    std::vector< std::vector<cv::Point2f> > imagePoints;

    cv::Mat cameraMatrix;
    cv::Mat distCoeffs;

    int flag;

    cv::Mat map1, map2;
    bool mustInitUndistort;

public:
    CameraCalibrator() : flag(0), mustInitUndistort(true) {}

    int addChessboardPoints(const std::vector<std::string> &filelist, cv::Size &boardSize, std::string windowName = "");

    void addPoints(const std::vector<cv::Point2f> &imageCorners, const std::vector<cv::Point3f> &objectCorners);

    double calibrate(const cv::Size imageSize);

    void setCalibrationFlag(bool radial8CoeffEnabled = false, bool tangentialParamEnabled = false);

    cv::Mat remap(const cv::Mat &image);


    cv::Mat getCameraMatrix() { return cameraMatrix; }

    cv::Mat getDistCoeffs() { return distCoeffs; }
};


#endif //PROJECT_CAMERACALIBRATOR_H
